package bb.lanxing.ali.behavior;

import android.content.Intent;

import com.baidu.mapapi.model.LatLng;
import com.github.mikephil.charting.utils.Utils;

import org.apache.commons.cli.HelpFormatter;

import bb.lanxing.App;
import bb.lanxing.manager.SharedManager;
import bb.lanxing.util.text.TextUtils;
import gov.nist.core.Separators;


public class AppBehavior {
    private static Behavior emptyBehavior;
    private final String prefix;

    AppBehavior(String str) {
        this.prefix = str;
    }

    public static AppBehavior route() {
        return new AppBehavior("lushu");
    }

    public static AppBehavior topic() {
        return new AppBehavior("topic");
    }

    public static AppBehavior routeSet() {
        return new AppBehavior("lushu_collection");
    }

    public static AppBehavior coupon() {
        return new AppBehavior("acoupon");
    }

    public static AppBehavior club() {
        return new AppBehavior("team");
    }

    public static AppBehavior news() {
        return new AppBehavior("news");
    }

    public static AppBehavior competition() {
        return new AppBehavior("competition");
    }

    public static AppBehavior activity() {
        return new AppBehavior("activity");
    }

    private Behavior createBehavior() {
        if (!App.getContext().isUserSignin()) {
            if (emptyBehavior == null) {
                emptyBehavior = new NonOperateBehavior();
            }
            return emptyBehavior;
        }
        emptyBehavior = null;
        BehaviorInner behaviorInner = new BehaviorInner(this.prefix);
        LatLng curLatLngWithMP = SharedManager.getInstance().getCurLatLngWithMP();
        if (curLatLngWithMP != null && curLatLngWithMP.latitude != Utils.DOUBLE_EPSILON && curLatLngWithMP.longitude != Utils.DOUBLE_EPSILON) {
            behaviorInner.positionType("ll");
            behaviorInner.position(curLatLngWithMP.longitude + Separators.COLON + curLatLngWithMP.latitude);
        } else {
            String curCityWithMP = SharedManager.getInstance().getCurCityWithMP();
            if (curCityWithMP != null) {
                behaviorInner.property("city", curCityWithMP);
            }
        }
        behaviorInner.amount(Utils.DOUBLE_EPSILON);
        behaviorInner.count(1.0d);
        return behaviorInner;
    }

    public Behavior view() {
        return createBehavior().view();
    }

    public Behavior click() {
        return createBehavior().click();
    }

    public Behavior searchClick() {
        return createBehavior().searchClick();
    }

    public Behavior collect() {
        return createBehavior().collect();
    }

    public Behavior uncollect() {
        return createBehavior().uncollect();
    }

    public Behavior comment() {
        return createBehavior().comment();
    }

    public Behavior download() {
        return createBehavior().download();
    }

    public Behavior create() {
        return createBehavior().create();
    }

    public Behavior share() {
        return createBehavior().share();
    }

    public Behavior use() {
        return createBehavior().use();
    }

    public Behavior join() {
        return createBehavior().join();
    }

    public Behavior consume() {
        return createBehavior().consume();
    }

    public static final String getTraceId(Intent intent) {
        if (intent != null) {
            return intent.getStringExtra("trace_id");
        }
        return null;
    }

    public static final void shareBehavior(int i, AppBehavior appBehavior, String str) {
        shareBehavior(i, appBehavior, null, str);
    }

    public static final void shareBehavior(int i, AppBehavior appBehavior, String str, String str2) {
        String str3 = i != 0 ? i != 1 ? i != 2 ? i != 3 ? i != 4 ? i != 7 ? null : "others" : Behavior.MEDIA_TYPE_SINA : Behavior.MEDIA_TYPE_WECHAT_CIRCLE : "wechat" : Behavior.MEDIA_TYPE_QQ_ZONE : Behavior.MEDIA_TYPE_QQ;
        if (str3 != null) {
            Behavior media = appBehavior.share().item(str2).media(str3);
            if (str != null) {
                media.trace(str);
            }
            media.submit();
        }
    }

    public static class BehaviorInner extends DefaultBehavior {
        private final String prefix;

        @Override
        public void submit() {
        }

        public BehaviorInner(String str) {
            this.prefix = str;
        }

        @Override
        public Behavior item(String str) {
            String str2;
            StringBuilder sb = new StringBuilder();
            sb.append(this.prefix);
            if (TextUtils.isEmptyOrNull(str)) {
                str2 = "";
            } else {
                str2 = HelpFormatter.DEFAULT_OPT_PREFIX + str;
            }
            sb.append(str2);
            return super.item(sb.toString());
        }
    }
}
